<html>
<head><meta charset="utf-8"><title>Creating static array to share with asm · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Creating.20static.20array.20to.20share.20with.20asm.html">Creating static array to share with asm</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="154218877"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Creating%20static%20array%20to%20share%20with%20asm/near/154218877" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Kyle Siefring <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Creating.20static.20array.20to.20share.20with.20asm.html#154218877">(Jan 03 2019 at 04:06)</a>:</h4>
<p>I have some assembly copied from a C project that has relies on an array defined as such<br>
<code>const int8_t ALIGN(dav1d_mc_subpel_filters[5][15][8], 8) = ...</code><br>
and I want to make sure that I'm not triggering undefined behavior.</p>
<p>Is the following rust code defined to have the same effect as <code>const int8_t ALIGN(FOO[16], 8) = { 42, 42, 42, ... };</code></p>
<div class="codehilite"><pre><span></span>#[repr(C, align(8))]
pub struct Aligned([i8; 16]);
#[no_mangle]
pub static FOO: Aligned = Aligned([42; 16]);
</pre></div>



<a name="154233224"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Creating%20static%20array%20to%20share%20with%20asm/near/154233224" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Creating.20static.20array.20to.20share.20with.20asm.html#154233224">(Jan 03 2019 at 11:09)</a>:</h4>
<p>Depends on what <code>ALIGN</code> is, but on most platforms, yes. To be extra pedantic it is the same as <code>struct { int8_t [16]; } __attribute__((align(8)))</code>, and there may be platforms where this is not exactly the same as an aligned array with 16 elements.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>